/**
 * related to start.ui
 * 
 * @Author : wzgl5533
 * @Timestamp : 2017-07-17
 */
// 引入组件
var nf = sm("do_Notification");
var do_App = sm("do_App");
var do_Page = sm("do_Page");
var do_Global = sm("do_Global");
// 加载外部动画js文件
var myAnimation = require("anim/myAnimation");
var test = require("source://view/welcome/test");
// 定义变量
var layout1 = ui("layout1");
var welcome_logo = ui("welcome_logo");
var welcome_title = ui("welcome_title");
var welcome_subdescribe = ui("welcome_subdescribe");
var welcome_copyright = ui("welcome_copyright");

// 给layout1定义一个平移和透明度动画
var layout1Anim = mm("do_Animation");
layout1Anim.fillAfter = true;

var layout1TransferAnimParams = myAnimation.getTransferParams();
layout1TransferAnimParams.delay = 0;
layout1TransferAnimParams.duration = 2000;
layout1TransferAnimParams.curve = "Linear";
layout1TransferAnimParams.autoReverse = false;
layout1TransferAnimParams.fromX = -672;
layout1TransferAnimParams.fromY = 0;
layout1TransferAnimParams.toX = 0;
layout1TransferAnimParams.toY = 0;

var layout1AlphaAnimParams = myAnimation.getAlphaParams();
layout1AlphaAnimParams.delay = 0;
layout1AlphaAnimParams.duration = 2000;
layout1AlphaAnimParams.curve = "Linear";
layout1AlphaAnimParams.autoReverse = false;
layout1AlphaAnimParams.alphaFrom = 0;
layout1AlphaAnimParams.alphaTo = 1;

layout1Anim.transfer(layout1TransferAnimParams, "a1");
layout1Anim.alpha(layout1AlphaAnimParams, "a2");

layout1.animate(layout1Anim);

// 给图标添加一个缩放动画
var welcome_logoAmim = mm("do_Animation");
welcome_logoAmim.fillAfter = true;

var welcome_logoScaleAmimParams = myAnimation.getScaleParams();
welcome_logoScaleAmimParams.delay = 0;
welcome_logoScaleAmimParams.duration = 2000;
welcome_logoScaleAmimParams.curve = "Linear";
welcome_logoScaleAmimParams.autoReverse = false;
welcome_logoScaleAmimParams.scaleFromX = 0;
welcome_logoScaleAmimParams.scaleFromY = 0;
welcome_logoScaleAmimParams.scaleToX = 1;
welcome_logoScaleAmimParams.scaleToY = 1;
welcome_logoScaleAmimParams.pivotX = 0.5;
welcome_logoScaleAmimParams.pivotY = 0.5;

welcome_logoAmim.scale(welcome_logoScaleAmimParams, "a3");

welcome_logo.animate(welcome_logoAmim);

// 标题和描述动画
var welcome_titleAnim = mm("do_Animation");
welcome_titleAnim.fillAfter = true;

var welcome_titleScaleAnimParams = welcome_logoScaleAmimParams;
welcome_titleScaleAnimParams.scaleFromX = 0;
welcome_titleScaleAnimParams.scaleFromY = 0;

var welcome_titleTransferAnimParams = layout1TransferAnimParams;
welcome_titleTransferAnimParams.fromX = 0;
welcome_titleTransferAnimParams.fromY = 100;
welcome_titleTransferAnimParams.toX = 0;
welcome_titleTransferAnimParams.toY = 0;

var welcome_titleAlphaAnimParams = layout1AlphaAnimParams;

welcome_titleAnim.scale(welcome_titleScaleAnimParams,"a4");
welcome_titleAnim.transfer(welcome_titleTransferAnimParams,"a5");
welcome_titleAnim.alpha(welcome_titleAlphaAnimParams, "a6");

welcome_title.animate(welcome_titleAnim);

welcome_subdescribe.animate(welcome_titleAnim);

//版权动画
var welcome_copyrightAmim = mm("do_Animation");
welcome_copyrightAmim.fillAfter = true;

var welcome_copyrightAlphaAnimParams = welcome_titleAlphaAnimParams;
var welcome_copyrightScaleAnimParams = welcome_logoScaleAmimParams;
welcome_copyrightScaleAnimParams.scaleFromX = 1;
welcome_copyrightScaleAnimParams.scaleFromY = 01;
welcome_copyrightScaleAnimParams.scaleToX = 1.2;
welcome_copyrightScaleAnimParams.scaleToY = 1.2;
welcome_copyrightAmim.alpha(welcome_copyrightAlphaAnimParams, "a7");
welcome_copyrightAmim.scale(welcome_copyrightScaleAnimParams, "a8");

welcome_copyright.animate(welcome_copyrightAmim,function(){
//动画执行完成后，开始检测是否可以直接登录
	test.hasUserInfo(do_Global.getMemory("data_label").user_data);
});


// 当前页面下，订阅android系统返回键的事件：3秒内连续点击两次退出应用
var canBack = false;
var delay3 = mm("do_Timer");

delay3.delay = 3000;
delay3.on("tick", function() {
	delay3.stop();
	canBack = false;
});
do_Page.on("back", function() {
	if (canBack) {
		do_App.closePage();
	} else {
		nf.toast("再次点击退出应用");
		canBack = true;
		delay3.start();
	}
});
